/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package apus.action.phonenumber;

import apus.action.Action;
import apus.action.ActionResult;
import apus.entity.PhoneNumber;
import apus.entity.RealPhoneNumber;
import apus.persistence.PhoneNumberDAO;
import apus.services.ServiceLocator;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Admin
 */
public class PhoneNumberDeleteAction implements Action {

    @Override
    public ActionResult execute(HttpServletRequest request, HttpServletResponse response) {
        if (request.getParameter("id") != null) {
            int id = Integer.parseInt(request.getParameter("id"));
            PhoneNumber phoneNumber = new RealPhoneNumber();
            phoneNumber.setId(id);
            ServiceLocator.getService(PhoneNumberDAO.class).delete(phoneNumber);
            request.getSession().setAttribute("win", "Phone number was removed");
        } else {
            request.getSession().setAttribute("fail", "Phone number wasn't removed");
        }
        List<PhoneNumber> phoneNumberList = ServiceLocator.getService(PhoneNumberDAO.class).findAll();
        request.setAttribute("phoneNumberList", phoneNumberList);
        return ActionResult.redirect("phoneNumber.list");
    }

    @Override
    public String getName() {
        return "phoneNumber.delete";
    }

}